package com.edais.service.imp;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.edais.dao.LoanDao;
import com.edais.domain.Loan;
import com.edais.domain.Scattered;
import com.edais.domain.UserChannelPoint;
import com.edais.service.LoanService;
import com.edais.service.UserChannelPointService;
import com.edais.util.CommonUtil;
import com.edais.util.Consts;
import com.edais.util.DecimalFormatUtil;
import com.edais.util.JsonUtil;
import com.edais.util.Message;
import com.edais.vo.LoanDetailVo;
import com.edais.vo.LoanLenderVo;
import com.edais.vo.LoanVo;

@Service

public class LoanServiceImp implements LoanService {
	private static final Log logger = LogFactory.getLog(LoanServiceImp.class);

	@Autowired
	private LoanDao loanDao;
	
	
	@Autowired
	UserChannelPointService userChannelPointService;

	@Override
	public String getLoanBaseInfoList(Map<String, Object> map)
			throws Exception {
		
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		
		// 获取计划id
//	    List idList = loanDao.getPlanByMain(map);
//	    String financeId = CommonUtil.listToString(idList);
//	    map.put("idList", idList);
	    
	    // 获取标的列表总条数
	    int total = loanDao.getLoanListSize(map);
	    if( 0 == total){
	    	rtnMap.put("totalNum", total);
	    	rtnMap.put("listSize", 0);
	    	rtnMap.put("list", new ArrayList());
	    	return CommonUtil.setResultStringCn(rtnMap, Consts.SUCCESS_CODE, Consts.SUCCESS_DESCRIBE,"");
	    }
	    
	    // 获取标的列表信息
		List<LoanVo> LoanVoList = loanDao.getLoanList(map);
		rtnMap.put("totalNum", total);
		rtnMap.put("listSize", LoanVoList.size());
    	rtnMap.put("list", LoanVoList);
    	return CommonUtil.setResultStringCn(rtnMap, Consts.SUCCESS_CODE, Consts.SUCCESS_DESCRIBE,"");
	}
	
	@Override
	public String getLoanDetail(Map<String, Object> map)
			throws Exception {
		
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		LoanDetailVo loanDetailVo = new LoanDetailVo();
		loanDetailVo.setRescode(Consts.SUCCESS_CODE);
		loanDetailVo.setResmsg_cn("");
	    
	    // 获取标的详细信息
		Map detailMap = loanDao.getLoanDetail(map);
		if(null != detailMap){
			loanDetailVo.setBorrowType(null == detailMap.get("BORROW_TYPE") ? "" : detailMap.get("BORROW_TYPE").toString());
			if(null == detailMap.get("REPAYMENT_TYPE")){
				loanDetailVo.setRepaymentType("");
			}else if("AVERAGE_CAPITAL_PLUS_INTEREST".equals(detailMap.get("REPAYMENT_TYPE"))){
				loanDetailVo.setRepaymentType("等额本息");
			}else if("AVERAGE_CAPITAL_PRINCIPAL".equals(detailMap.get("REPAYMENT_TYPE"))){
				loanDetailVo.setRepaymentType("等额本金");
			}else if("PWRIOD_REPAYS_CAPTITAL".equals(detailMap.get("REPAYMENT_TYPE"))){
				loanDetailVo.setRepaymentType("每月付息，到期还本");
			}else if("MATURITY_DEBT".equals(detailMap.get("REPAYMENT_TYPE"))){
				loanDetailVo.setRepaymentType("到期还本付息");
			}
			loanDetailVo.setProductType(null == detailMap.get("PRODUCT_TYPE") ? "" : detailMap.get("PRODUCT_TYPE").toString());
			loanDetailVo.setEndTime(null == detailMap.get("END_TIME") ? "" : detailMap.get("END_TIME").toString());
			loanDetailVo.setRealName(null == detailMap.get("REAL_NAME") ? "" : detailMap.get("REAL_NAME").toString());
			if(null == detailMap.get("GENDER")){
				loanDetailVo.setGender("");
			}else if("FEMALE".equals(detailMap.get("GENDER"))){
				loanDetailVo.setGender("女");
			}else if("MALE".equals(detailMap.get("GENDER"))){
				loanDetailVo.setGender("男");
			}
			loanDetailVo.setAge(null == detailMap.get("AGE") ? "" : detailMap.get("AGE").toString());
			loanDetailVo.setEducationalType(null == detailMap.get("EDUCATIONAL_TYPE") ? "" : detailMap.get("EDUCATIONAL_TYPE").toString());
			loanDetailVo.setIncomeMonthly(null == detailMap.get("EDUCATIONAL_TYPE") ? "" : detailMap.get("EDUCATIONAL_TYPE").toString());
			}
		
		return JsonUtil.getJsonStringFromObject(loanDetailVo);
	}
	
	@Override
	public Loan getLoanDetailByLoanId(Map<String, Object> map)
			throws Exception {
		
	    // 获取标的详细信息
		Loan loan = loanDao.getLoanDetailByLoanId(map);
		
		return loan;
	}
	
	@Override
	public Loan getLoanDetailBySLoanId(Map<String, Object> map)
			throws Exception {
		
	    // 获取标的详细信息
		Loan loan = loanDao.getLoanDetailBySLoanId(map);
		
		return loan;
	}
	
	@Override
	public Loan getLoanDetailByFinaceId(Map<String, Object> map)
			throws Exception {
		
	    // 获取标的详细信息
		Loan loan = loanDao.getLoanDetailByFinaceId(map);
		
		return loan;
	}

	@Override
	public String getUserListByLoanIdForWx(Map<String, Object> map) throws Exception {
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		List<LoanLenderVo> loanLenderVoList = new ArrayList<LoanLenderVo>();
		//Add By ZuoJun For LoanServiceImp In 2016-4-3 Begin
		String scatteredLoanId = map.get("scatteredLoanId").toString();

		
	
		
		String transCode = "E330022";
//		String transCode = "E360009";
		Map<String,Object> coreMap = new HashMap<String,Object>();
		coreMap.put("scatteredLoanId", map.get("scatteredLoanId"));
//		coreMap.put("loanId", map.get("loanId"));
		coreMap.put("pageSize", map.get("pageSize"));
		coreMap.put("current", map.get("currentPage"));
		
		// 构建json字符串
		String jsonStr = CommonUtil.constructJsonStr(transCode, null, coreMap);
		// 调用核心接口
		String rtnStr = CommonUtil.getCoreValue(jsonStr);
		JSONObject jsonObject = JSONObject.fromObject(rtnStr);
		
		// rescode = "00000"
		if(Consts.SUCCESS_CODE.equals(jsonObject.getString("rescode"))){
			JSONArray jsonArr = jsonObject.getJSONArray("list");
			if(jsonArr != null && jsonArr.size() > 0){
				for(int i = 0; i < jsonArr.size(); i++){
					JSONObject jsonObj = jsonArr.getJSONObject(i);
					LoanLenderVo loanLenderVo = new LoanLenderVo();
					String realName = jsonObj.getString("realName");
					if(null != realName && !"".equals(realName) && realName.length() > 1){
						//*处理
						/*realName = "*"+realName.substring(1,realName.length());*/
						int nameLength = realName.length();
						String endStar = "";
						for(int a=1;a<nameLength;a++){
							endStar+="*";
						}
						realName = realName.substring(0,1)+endStar;
					}
					loanLenderVo.setRealName(realName);
					loanLenderVo.setBuyDate(jsonObj.getString("creditDate"));
					loanLenderVo.setBuyMoney(jsonObj.getString("investAmount"));
					loanLenderVo.setImageIconDispose(jsonObj.getString("imageIconDispose"));
					
					loanLenderVoList.add(loanLenderVo);
					
				}
				rtnMap.put("totalNum", jsonObject.getString("totalNum"));
				rtnMap.put("listSize", loanLenderVoList.size());
				rtnMap.put("list", loanLenderVoList);
				
			}else{
				rtnMap.put("totalNum", 0);
				rtnMap.put("listSize", 0);
				rtnMap.put("list", new ArrayList()); 
			}
			// 设置返回code
			return CommonUtil.setResultStringCn(rtnMap, Consts.SUCCESS_CODE, Consts.SUCCESS_DESCRIBE,"");
		}else {
			logger.debug("=====核心接口调用异常=====");
			logger.debug("rescode：" + jsonObject.getString("rescode") + "；  resmsg：" + jsonObject.getString("resmsg"));
			return CommonUtil.setResultStringCn(rtnMap, Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);
		}
	}
	
	@Override
	public String getUserListByLoanId(Map<String, Object> map) throws Exception {
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		List<LoanLenderVo> loanLenderVoList = new ArrayList<LoanLenderVo>();
				
		String transCode = "E360009";
		Map<String,Object> coreMap = new HashMap<String,Object>();
		coreMap.put("loanId", map.get("loanId"));
		coreMap.put("pageSize", map.get("pageSize"));
		coreMap.put("current", map.get("currentPage"));
		
		// 构建json字符串
		String jsonStr = CommonUtil.constructJsonStr(transCode, null, coreMap);
		// 调用核心接口
		String rtnStr = CommonUtil.getCoreValue(jsonStr);
		JSONObject jsonObject = JSONObject.fromObject(rtnStr);
		
		// rescode = "00000"
		if(Consts.SUCCESS_CODE.equals(jsonObject.getString("rescode"))){
			JSONArray jsonArr = jsonObject.getJSONArray("list");
			if(jsonArr != null && jsonArr.size() > 0){
				for(int i = 0; i < jsonArr.size(); i++){
					JSONObject jsonObj = jsonArr.getJSONObject(i);
					LoanLenderVo loanLenderVo = new LoanLenderVo();
					String realName = jsonObj.getString("realName");
					if(null != realName && !"".equals(realName) && realName.length() > 1){
						//*处理
						/*realName = "*"+realName.substring(1,realName.length());*/
						int nameLength = realName.length();
						String endStar = "";
						for(int a=1;a<nameLength;a++){
							endStar+="*";
						}
						realName = realName.substring(0,1)+endStar;
					}
					loanLenderVo.setRealName(realName);
					loanLenderVo.setBuyDate(jsonObj.getString("creditDate"));
					loanLenderVo.setBuyMoney(jsonObj.getString("investAmount"));
					loanLenderVo.setImageIconDispose(jsonObj.getString("imageIconDispose"));
					
					loanLenderVoList.add(loanLenderVo);
					
				}
				rtnMap.put("totalNum", jsonObject.getString("totalNum"));
				rtnMap.put("listSize", loanLenderVoList.size());
				rtnMap.put("list", loanLenderVoList);
				
			}else{
				rtnMap.put("totalNum", 0);
				rtnMap.put("listSize", 0);
				rtnMap.put("list", new ArrayList()); 
			}
			// 设置返回code
			return CommonUtil.setResultStringCn(rtnMap, Consts.SUCCESS_CODE, Consts.SUCCESS_DESCRIBE,"");
		}else {
			logger.debug("=====核心接口调用异常=====");
			logger.debug("rescode：" + jsonObject.getString("rescode") + "；  resmsg：" + jsonObject.getString("resmsg"));
			return CommonUtil.setResultStringCn(rtnMap, Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);
		}
	}
	
	@Override
	public String queryDepositLoanLenderDetailCount(Map<String, Object> map) throws Exception {
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		List<LoanLenderVo> loanLenderVoList = new ArrayList<LoanLenderVo>();
		
//		String transCode = "E330022";
		String transCode = "E360010";
		Map<String,Object> coreMap = new HashMap<String,Object>();
		coreMap.put("loanId", map.get("loanId"));
		
		// 构建json字符串
		String jsonStr = CommonUtil.constructJsonStr(transCode, null, coreMap);
		// 调用核心接口
		String rtnStr = CommonUtil.getCoreValue(jsonStr);
		JSONObject jsonObject = JSONObject.fromObject(rtnStr);
		String totalNum = "";
		
		// rescode = "00000"
		if(Consts.SUCCESS_CODE.equals(jsonObject.getString("rescode"))){
			totalNum = jsonObject.getString("totalNum");
			// 设置返回code
		}else {
			logger.debug("=====核心接口调用异常=====");
			logger.debug("rescode：" + jsonObject.getString("rescode") + "；  resmsg：" + jsonObject.getString("resmsg"));
		}
		return totalNum;
	}
	
	/**
	 * 散标列表
	 */
	@Override
	public List<Scattered> queryScatteredLoan(Map<String, Object> map)  throws Exception{
		return loanDao.queryScatteredLoan(map);
	}
	
	/**
	 * 散标列表
	 */
	@Override
	public Map<String, Object> queryScatteredLoanInfo(Map<String, Object> params)  throws Exception{
				
		//获取上架产品总数
		int totalNum = loanDao.queryScatteredLoanInfoCount(params);
		
		List<Scattered> scatteredList = loanDao.queryScatteredLoanInfo(params);
		
		/**
		 * 剩余金额小于起头金额，返回100%
		 * 当产品已经超过下架时间，返回100%
		 */
		List<Map<String,Object>> resultListMap = new ArrayList<Map<String,Object>>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		Map<String, Object> map2 = new HashMap<String, Object>();
		String investUserNum = "";
		
		StringBuffer loadIdBf=new StringBuffer();
		for(int i =0;i<scatteredList.size();i++){
			loadIdBf.append(String.valueOf(scatteredList.get(i).getId())+",");
		}
		String loadId=loadIdBf.toString();
		Map<String,Object> listEx=null;
		
		if(loadId.lastIndexOf(",")!=-1){
			loadId=loadId.substring(0,loadId.lastIndexOf(","));
			logger.debug("queryOrderByIdPeopleNumEx传值参数-------"+loadId);
			map2.put("loanId", loadId);
			listEx=queryOrderByIdPeopleNumEx(map2);
			logger.debug("queryOrderByIdPeopleNumEx返回结果-------"+listEx);
		}
		
		//获取用户渠道等级积分数据
		UserChannelPoint userChannelPoint = null;
		
		String userId = String.valueOf(params.get("userId"));
		if (userId != null && !"".equals(userId) && !"null".equals(userId)) {
			Map<String,Object> parm = new HashMap<String, Object>();
			parm.put("userId", userId);
			userChannelPoint = userChannelPointService.findChannelPointByParm(parm);
		}

		for(int i =0;i<scatteredList.size();i++){
			Scattered sc = scatteredList.get(i);
			Map<String,Object> scMap = new HashMap<String,Object>();
			scMap.put("scatteredLoanId", sc.getId());//id
			scMap.put("productName", sc.getProductName());//
			scMap.put("borrowType", sc.getBorrowType());
			scMap.put("annualRate", sc.getAnnualRate());
			scMap.put("remanPeriods", sc.getRemanPeriods()); //剩余期数
			scMap.put("contactAmount", sc.getContactAmount());
			scMap.put("finishedRatio", DecimalFormatUtil.getDecimalFormat0(BigDecimal.ONE.compareTo(sc.getFinishedRatio())>0 && BigDecimal.ZERO.compareTo(sc.getFinishedRatio())<0?BigDecimal.ONE:sc.getFinishedRatio()));
			scMap.put("remanAmount", sc.getRemanAmount());
			scMap.put("perServingAmount", sc.getPerServingAmount());
			scMap.put("investMinAmount", sc.getInvestMinAmount());
			scMap.put("openSelling", sc.getOpenSelling());
			scMap.put("loanId", sc.getBidId());
			scMap.put("planId", sc.getPlanId());
			scMap.put("isAdjustRate", sc.getIsAdjustRate());
			scMap.put("remanDays", sc.getRemanDays());	//剩余天数（替换剩余期数）			
			BigDecimal adjustRate = BigDecimal.ZERO; 
			if ("Y".equals(sc.getIsAdjustRate())) {
				if (userChannelPoint != null) {
					adjustRate = sc.getMaxAdjustRate().multiply(
							new BigDecimal(userChannelPoint.getFixFloatRateChannel()));
				}
			}
			//调整利率
			scMap.put("adjustRate", adjustRate.setScale(1, RoundingMode.DOWN));

			// 获取标的列表人数
			if(listEx!=null&&listEx.size()!=0&&listEx.size()==scatteredList.size()){
				if(listEx.containsKey(String.valueOf(sc.getId()))){
					scMap.put("investUserNum", listEx.get(String.valueOf(sc.getId())));
				}else{
					scMap.put("investUserNum", "1");
				}
			}else{
				map2.put("loanId", sc.getId());
				investUserNum = queryOrderByIdPeopleNum(map2);
				scMap.put("investUserNum", investUserNum);
			}
			resultListMap.add(scMap);
		}
		
		Map<String, Object> mapResult = new HashMap<String, Object>();
		mapResult.put("totalNum", totalNum);
		mapResult.put("listSize", String.valueOf(resultListMap.size()));
		mapResult.put("list", resultListMap);
		mapResult.put("resmsg_cn", "");		
		
		return mapResult;
	}
	
	
//	/**
//	 * 散标列表
//	 */
//	@Override
//	public List<Scattered> queryScatteredLoanInfo(Map<String, Object> map)  throws Exception{
//		return loanDao.queryScatteredLoanInfo(map);
//	}
	
	/**
	 * 散标列表总数
	 */
	@Override
	public String queryScatteredLoanCount(Map<String,Object> map)  throws Exception{
		return loanDao.queryScatteredLoanCount(map);
	}
	/**
	 * 散标列表总数
	 */
	@Override
	public Integer queryScatteredLoanInfoCount(Map<String,Object> map)  throws Exception{
		return loanDao.queryScatteredLoanInfoCount(map);
	}
	
	/**
	 * 取得标的的图片信息
	 */
	@Override
	public String getLenderMaterial(Map<String,Object> map)  throws Exception{
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		
		List list = loanDao.getLenderMaterials(map);
		
		rtnMap.put("listSize", null == list? 0: list.size());
		rtnMap.put("list", list); 
		
		return CommonUtil.setResultStringCn(rtnMap, Consts.SUCCESS_CODE, Consts.SUCCESS_DESCRIBE,"");
	}

	@Override
	public List<Scattered> queryWxAndAppLoan() throws Exception {
		return loanDao.queryWxAndAppLoan();
	}
	
	@Override
	public String queryBitShowNamePeriod() throws Exception {
		return loanDao.queryBitShowNamePeriod();
	}
	
	@Override
	public String queryBitShowNameCurrent() throws Exception {
		return loanDao.queryBitShowNameCurrent();
	}
	
	@Override
	public String queryOrderByIdPeopleNum(Map<String, Object> map) throws Exception {
		
		String transCode = "E360011";
		Map<String,Object> coreMap = new HashMap<String,Object>();
		coreMap.put("loanId", map.get("loanId"));
		
		// 构建json字符串
		String jsonStr = CommonUtil.constructJsonStr(transCode, null, coreMap);
		// 调用核心接口
		String rtnStr = CommonUtil.getCoreValue(jsonStr);
		JSONObject jsonObject = JSONObject.fromObject(rtnStr);
		String totalNum = "";
		
		// rescode = "00000"
		if(Consts.SUCCESS_CODE.equals(jsonObject.getString("rescode"))){
			totalNum = jsonObject.getString("totalNum");
			// 设置返回code
		}else {
			logger.debug("=====核心接口调用异常=====");
			logger.debug("rescode：" + jsonObject.getString("rescode") + "；  resmsg：" + jsonObject.getString("resmsg"));
		}
		return totalNum;
	}

	@Override
	public Scattered queryScatteredByLoanId(Map<String, Object> map) throws Exception {
		return this.loanDao.queryScatteredByLoanId(map);
	}

	@Override
	public Map<String,Object> queryOrderByIdPeopleNumEx(
			Map<String, Object> map2) throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		
		String transCode = "E360013";
		Map<String,Object> coreMap = new HashMap<String,Object>();
		coreMap.put("loanId", map2.get("loanId"));
		
		// 构建json字符串
		String jsonStr = CommonUtil.constructJsonStr(transCode, null, coreMap);
		// 调用核心接口
		String rtnStr = CommonUtil.getCoreValue(jsonStr);
		JSONObject jsonObject = JSONObject.fromObject(rtnStr);
		
		// rescode = "00000"
		if(Consts.SUCCESS_CODE.equals(jsonObject.getString("rescode"))){
			JSONArray jsonArr = jsonObject.getJSONArray("list");
			if(jsonArr != null && jsonArr.size() > 0){
				for(int i = 0; i < jsonArr.size(); i++){
					JSONObject jsonObj = jsonArr.getJSONObject(i);
					String scatteredLoanId = jsonObj.getString("SCATTEREDLOANID");
					String totalNum = jsonObj.getString("TOTALNUM");
					rtnMap.put(scatteredLoanId, totalNum);	
				}
			}
			//如果返回的与传给的上架个数不符,将置初始值0
			if(rtnMap!=null&&rtnMap.size()!=0){
				String[] loadIds=null;
				if(map2.get("loanId")!=null&&!"".equals(map2.get("loanId"))
						&&((String)map2.get("loanId")).indexOf(",")!=-1){
					loadIds=((String)map2.get("loanId")).split("\\,");
				}else{
					loadIds=new String[]{};
				}
				for (int i = 0; i < loadIds.length; i++) {
					if(!rtnMap.containsKey(loadIds[i])){
						rtnMap.put(loadIds[i], "0");
					}
				}
			}
			// 设置返回code
		}else {
			logger.debug("=====queryOrderByIdPeopleNumEx核心接口调用异常=====");
			logger.debug("rescode：" + jsonObject.getString("rescode") + "；  resmsg：" + jsonObject.getString("resmsg"));
		}
		return rtnMap;
	}

	@Override
	public Map<String, Object> queryDepositLoanLenderDetailCountEx(
			Map<String, Object> map2) throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> rtnMap = new HashMap<String, Object>();

		String transCode = "E360014";
		Map<String,Object> coreMap = new HashMap<String,Object>();
		coreMap.put("bidId", map2.get("bidId"));
		// 构建json字符串
		String jsonStr = CommonUtil.constructJsonStr(transCode, null, coreMap);
		// 调用核心接口
		String rtnStr = CommonUtil.getCoreValue(jsonStr);
		JSONObject jsonObject = JSONObject.fromObject(rtnStr);

		// rescode = "00000"
		if(Consts.SUCCESS_CODE.equals(jsonObject.getString("rescode"))){
			JSONArray jsonArr = jsonObject.getJSONArray("list");
			if(jsonArr != null && jsonArr.size() > 0){
				for(int i = 0; i < jsonArr.size(); i++){
					JSONObject jsonObj = jsonArr.getJSONObject(i);
					String bidId = jsonObj.getString("BIDID");
					String totalNum = jsonObj.getString("TOTALNUM");
					rtnMap.put(bidId, totalNum);	
				}
			}
			//如果返回的与传给的标的个数不符,将置初始值0
			if(rtnMap!=null&&rtnMap.size()!=0){
				String[] bidIds=null;
				if(map2.get("bidId")!=null&&!"".equals(map2.get("bidId"))
						&&((String)map2.get("bidId")).indexOf(",")!=-1){
					bidIds=((String)map2.get("bidId")).split("\\,");
				}else{
					bidIds=new String[]{};
				}
				for (int i = 0; i < bidIds.length; i++) {
					if(!rtnMap.containsKey(bidIds[i])){
						rtnMap.put(bidIds[i], "0");
					}
				}
			}
			// 设置返回code
		}else {
			logger.debug("=====queryDepositLoanLenderDetailCountEx核心接口调用异常=====");
			logger.debug("rescode：" + jsonObject.getString("rescode") + "；  resmsg：" + jsonObject.getString("resmsg"));
		}
		return rtnMap;
	}

	@Override
	public String currentInvestList(Map<String, Object> map) throws Exception {
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		List<LoanLenderVo> loanLenderVoList = new ArrayList<LoanLenderVo>();
		String transCode = "E360017";
		Map<String,Object> coreMap = new HashMap<String,Object>();
		String current=map.get("currentPage")+"";
		String pageSize=map.get("pageSize")+"";
		int totlePages=0;
//		coreMap.put("loanId", map.get("loanId"));
		coreMap.put("pageSize",pageSize);
		coreMap.put("current", current);
		
		// 构建json字符串
		String jsonStr = CommonUtil.constructJsonStr(transCode, null, coreMap);
		// 调用核心接口
		String rtnStr = CommonUtil.getCoreValue(jsonStr);
		JSONObject jsonObject = JSONObject.fromObject(rtnStr);
		
		if(Consts.SUCCESS_CODE.equals(jsonObject.getString("rescode"))){
			JSONArray jsonArr = jsonObject.getJSONArray("list");
			if(jsonArr != null && jsonArr.size() > 0){
				for(int i = 0; i < jsonArr.size(); i++){
					JSONObject jsonObj = jsonArr.getJSONObject(i);
					LoanLenderVo loanLenderVo = new LoanLenderVo();
					String realName = jsonObj.getString("realName");
					if(null != realName && !"".equals(realName) && realName.length() > 1){
						//*处理
						int nameLength = realName.length();
						String endStar = "";
						for(int a=1;a<nameLength;a++){
							endStar+="*";
						}
						realName = realName.substring(0,1)+endStar;
					}
					loanLenderVo.setRealName(realName);
					loanLenderVo.setBuyDate(jsonObj.getString("creditDate"));
					loanLenderVo.setBuyMoney(jsonObj.getString("investAmount"));
					loanLenderVo.setImageIconDispose(jsonObj.getString("imageIconDispose"));
					loanLenderVoList.add(loanLenderVo);
				}
				if(!StringUtils.isBlank(jsonObject.getString("totalNum"))){
					int totalSize=Integer.valueOf(jsonObject.getString("totalNum"));
					if(totalSize%Integer.valueOf(pageSize)==0){
						totlePages=totalSize/Integer.valueOf(pageSize);
					}else{
						totlePages=totalSize/Integer.valueOf(pageSize)+1;
					}
				}
				rtnMap.put("totalNum", jsonObject.getString("totalNum"));
				rtnMap.put("listSize", loanLenderVoList.size());
				rtnMap.put("current", current);
				rtnMap.put("totlePages", totlePages);
				rtnMap.put("list", loanLenderVoList);
			}else{
				rtnMap.put("totalNum", 0);
				rtnMap.put("current", current);
				rtnMap.put("listSize", 0);
				rtnMap.put("totlePages", totlePages);
				rtnMap.put("list", new ArrayList()); 
			}
			// 设置返回code
			return CommonUtil.setResultStringCn(rtnMap, Consts.SUCCESS_CODE, Consts.SUCCESS_DESCRIBE,"");
		}else {
			logger.debug("=====核心接口调用异常=====");
			logger.debug("rescode：" + jsonObject.getString("rescode") + "；  resmsg：" + jsonObject.getString("resmsg"));
			return CommonUtil.setResultStringCn(rtnMap, Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);
		}
	}

	@Override
	public String currentInvestNum(Map<String, Object> map) throws Exception {
		// TODO Auto-generated method stub
		String transCode = "E360018";
		Map<String,Object> coreMap = new HashMap<String,Object>();
//		coreMap.put("loanId", map.get("loanId"));
		Map<String, Object> rtnMap = new HashMap<String, Object>();
		
		// 构建json字符串
		String jsonStr = CommonUtil.constructJsonStr(transCode, null, coreMap);
		// 调用核心接口
		String rtnStr = CommonUtil.getCoreValue(jsonStr);
		JSONObject jsonObject = JSONObject.fromObject(rtnStr);
		String peoplenum = "";
		
		// rescode = "00000"
		if(Consts.SUCCESS_CODE.equals(jsonObject.getString("rescode"))){
			peoplenum = jsonObject.getString("peoplenum");
			rtnMap.put("peoplenum", peoplenum);
			return CommonUtil.setResultStringCn(rtnMap, Consts.SUCCESS_CODE, Consts.SUCCESS_DESCRIBE,"");
			// 设置返回code
		}else {
			logger.debug("=====核心接口调用异常=====");
			logger.debug("rescode：" + jsonObject.getString("rescode") + "；  resmsg：" + jsonObject.getString("resmsg"));
			rtnMap.put("peoplenum", "0");
			return CommonUtil.setResultStringCn(rtnMap, Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,Message.CnDescriptionExpression.BUSINESSE_ERROR);
		}
	}
	
}
